package com.example.shengyin.frontController;

import com.alibaba.fastjson2.JSON;
import com.example.shengyin.entity.*;
import com.example.shengyin.service.ArticleService;
import com.example.shengyin.service.SymService;
import com.example.shengyin.util.Result;
import com.example.shengyin.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * AdminController
 * 
 * @author ruoyi
 * @date 2023-07-29
 */
@RestController
@RequestMapping("/front/sym")
@Validated
@CrossOrigin(origins = "*", maxAge = 3600,allowCredentials="true")
//swagger

@Api(tags = "FrontSymController", description = "服务群体")
public class FrontSymController
{
    @Autowired
    private SymService service;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private ArticleService service2;
    @ApiOperation("服务群体 症状种类")
    @GetMapping("/findSyms")
    public Result findSyms()
    {
        Map map=new HashMap<>();
        List<Sym> symtype = service.findSymtype();
        for (int i = 0; i < symtype.size(); i++) {
            List<Sym> list = service.list(new Page(1, 20), symtype.get(i).getId());
            map.put(symtype.get(i).getSymtypename(),list);
        }

        return Result.success(map);
    }


    @ApiOperation("新方法，获取服务群体")
    @GetMapping("/findSymtype")
    public Result findSymtype()
    {
        List<common> symtype = service.symtype();

        return Result.success(symtype);
    }

    @ApiOperation("新方法，获取使所有的症状，分页了,这个是下面的展示的带头像的")
    @GetMapping("/findSymList")
    public Result findSymList( int page,int limit,int symtype)
    {
        common common = new common();
        common.put("pagestart",(page*10)-10);
        common.put("limit",limit);
        common.put("symtype",symtype);
        int count = service.count((long) symtype);
        List<com.example.shengyin.entity.common> symlist = service.symlist(common);
        if(symlist==null)
        {
            return Result.success("没有这么多的数据");
        }
        Page page1=new Page(page, limit);
        page1.setData(symlist);
        page1.setCount(count);
        return Result.success(page1);
    }
    @ApiOperation("新方法，获取使所有的症状，列表用的，只有id,症状，症状种类三个信息")
    @GetMapping("/findNewSyms")
    public Result findNewSyms()
    {
        List<common> symtype = service.syminfo();
        return Result.success(symtype);
    }


    @ApiOperation("单个查找")
    @GetMapping(value = "/findSymsDetail/{id}")
    public Result select(@PathVariable(value = "id") Long id)
    {
        Sym select = service.select(id);
        if(select==null)
            return Result.error("没有找到数据");
        return Result.success(select);
    }
    @GetMapping(value = "/findSuccessInfo/{page}/{limit}")
    public Result findSpeechs(@PathVariable(value = "page") int page1,
                              @PathVariable(value = "limit")int limit)
    {
        Page page=new Page(page1,limit);
        int comnews = service2.countTotall(null, "SuccessInfo", null, null, null);
        List<ArticleSimple> articles = service2.articleList2(page, null, "SuccessInfo", null, null, null);
        if(comnews==0||articles==null)
            return Result.success(page,"没有数据");
        page.setCount(comnews);
        page.setData(articles);
        return Result.success(page);
    }

}
